<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="g" uri="http://www.trkj.com/crm"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息</title>

<style type="text/css">
.by {
	padding: 10px;
}

.line {
	margin-top: 10px;
}
</style>

<link rel="shortcut icon"
	href="<c:url value="/easyui/css/images/favicon.ico"/>" />
<link rel="stylesheet" href="<c:url value="/css/flipclock.css"/>">
<link href="<c:url value="/css/CalcSS3.css"/>" rel="stylesheet"
	type="text/css" />
<link href="<c:url value="/css/index.css"/>" rel="stylesheet"
	type="text/css" />
<link href="<c:url value="/easyui/css/easyui.css"/>" rel="stylesheet"
	type="text/css">
<link href="<c:url value="/easyui/css/easyui_animation.css"/>"
	rel="stylesheet" type="text/css">

<link href="<c:url value="/easyui/css/easyui_plus.css" />"
	rel="stylesheet" type="text/css">
<link href="<c:url value="/easyui/css/insdep_theme_default.css" />"
	rel="stylesheet" type="text/css">
<link href="<c:url value="/easyui/css/icon.css" />" rel="stylesheet"
	type="text/css">
<link
	href="<c:url value="/easyui/css/font-awesome-4.7.0/css/font-awesome.min.css" />"
	rel="stylesheet" type="text/css">
<!-- 引入 ECharts 文件 -->
<script type="text/javascript" src="<c:url value="/js/echarts.js"/>"></script>
<!--放入自定义的图表-->

<script type="text/javascript" src="<c:url value="/js/monitor.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/easyui/js/jquery.min.js"/>"></script>
<%--<script type="text/javascript" src="js/jquery.js"></script>--%>
<script type="text/javascript"
	src="<c:url value="/easyui/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/easyui/js/jquery.insdep-extend.min.js"/>">
	
</script>


</head>
<body>

<script type="text/javascript">
	$.extend($.fn.validatebox.defaults.rules, {

		phoneNum : { //验证手机号   
			validator : function(value, param) {
				return /^1[3-8]+\d{9}$/.test(value);
			},
			message : '请输入正确的手机号码。'
		}
	});
	$(function() {
		$("#all-user").linkbutton({
			onClick : function() {
				$("#yk-uesr-info").datagrid({
					url : "query-All-PageCount",
					method : "post"
				});
				$("#yk-uesr-info").datagrid("reload");
			}
		});

		$("#empower-user").linkbutton({
			onClick : function() {
				var row = $("#yk-uesr-info").datagrid("getSelected");

				if (row) {
					var uId = row.uId;
					$("#yk-role-to-user-sq").dialog({
						uId : uId,
						onOpen : function() {
							$("#tree-user-role").tree({
								url : "get-Role-For-Grants?uId=" + uId
							});
						}
					});

					$("#yk-role-to-user-sq").window("open");
				} else {
					$.messager.alert("提示", "请选择要分配角色的用户！");
				}
			}
		});

		$("#user-grant-roles-ave").linkbutton({onClick:function(){
			 $("<form method='post' action='grant-Role-To-Users'>").appendTo(document.body).form({
			        onSubmit:function(params){                       
			           params.uId = $("#yk-role-to-user-sq").dialog("options").uId;
			           var nodes = $("#tree-user-role").tree("getChecked");
			           if(nodes){
			               var j = 0;
			               for(var i = 0;i < nodes.length; i++){
			                  if(!(nodes[i].children)){
			                     params["rids["+ j +"]"] = nodes[i].id;
			                     j++;
			                  }
			               }
			           }
			        },
			        success:function(r){
			           r = eval("("+ r +")");
			           if(r.success){
			              $("#yk-role-to-user-sq").window("close");
			              $.messager.alert("提示", "用户分配角色成功！");
			           }else{
			               $.messager.alert("提示", r.message);
			           }
			        }                                                
			       
			   }).submit();
		}});
		
		$("#user-grant-role-close").linkbutton({
			onClick : function() {
				$("#yk-role-to-user-sq").window("close");
			}
		});

		$("#append-user").linkbutton({
			onClick : function() {
				$("#yk-add-user").window("open");
			}
		});

		$("#modify-user").linkbutton({
			onClick : function() {
				var row = $("#yk-uesr-info").datagrid("getSelected");
				if (row) {
					$("#yk-update-user").window("open");
				} else {
					$.messager.alert("提示", "请选择要修改的用户！");
				}

			}
		});

		$("#deleting-user").linkbutton({
			onClick : function() {
				var row = $("#yk-uesr-info").datagrid("getSelected");
				if (row) {
					$.messager.confirm("询问", "你确定要删除此用户吗？", function(v) {
						if (v) {
							$.post("delete-One-User", {
								uId : row.uId
							}, function(r) {
								if (r.success) {
									$("#yk-uesr-info").datagrid("reload");
									$.messager.alert("提示", "删除成功！");
								} else {
									$.messager.alert("提示", r.message);
								}
							});
						}
					});

				} else {
					$.messager.alert("提示", "请选择要删除的用户！");
				}
			}
		});

		$("#reset-password").linkbutton({
			onClick : function() {
				var row = $("#yk-uesr-info").datagrid("getSelected");
				if (row) {
					$.messager.confirm("询问", "你确定要重置密码吗？", function(v) {
						if (v) {
							$.post("reset-OnePassword", {
								uId : row.uId
							}, function(r) {
								if (r.success) {
									$("#yk-uesr-info").datagrid("reload");
									$.messager.alert("提示", "重置密码成功！");
								} else {
									$.messager.alert("提示", r.message);
								}
							});
						} else {
						}
					});
				} else {
					$.messager.alert("提示", "请选择要重置密码的用户！");
				}
			}
		});
		
		$("#yk-uesr-info").datagrid({
	         onBeforeSelect: function(index,row){
	             var row =$("#yk-uesr-info").datagrid("getSelected");
	             var curRowindex = $("#yk-uesr-info").datagrid("getRowIndex",row);
	             if(curRowindex != index) {return true;}
	             else{ $("#yk-uesr-info").datagrid("unselectRow",index); return false;}
	         } 
		 });
		

	});
</script>
<div id="g" style="width: 100%;height: 100%">
	<table id="yk-uesr-info" class="easyui-datagrid" 
		data-options="
	       fit:true,fitColumns:true, autoRowHeight:false,nowrap:false,rownumbers:true,
	           striped:true,singleSelect:true,toolbar:'#yk-user-control',
	           pagination:true,url:'query-All-PageCount',method:'post',
	           pageList:[5,10,15,20,25],pageSize:10,">
		<thead>
			<tr>
				<th data-options="field:'cccc',width:20,checkbox:true"></th>
				<th data-options="field:'uId',width:20">用户ID</th>
				<th data-options="field:'uname',width:30">用户名</th>
<!-- 				<th data-options="field:'upassword',width:30">密码</th> -->
				<th data-options="field:'urealName',width:20">真实姓名</th>
				<th data-options="field:'phone',width:30">电话</th>
				<th data-options="field:'userAddress',width:50" >用户地址</th>
				<th data-options="field:'uimage',
				        formatter: function (value, row, index) {
                            return '<img  src=' + value + '/>';
                        },width:40" >用户头像</th>
				<th data-options="field:'ucreateTime',width:30">创建时间</th>
				<th
					data-options="field:'crmDept',width:30,
					   formatter:function(value){
					return  value.crmDeptno;
				}">部门ID</th>
			</tr>
		</thead>
		<tbody>


		</tbody>
	</table>
	</div>
	<div id="yk-user-control">
		<span><a id="append-user" class="easyui-linkbutton"
			data-options="iconCls:'icon-add'">添加用户</a> </span> 
			<span><a
			id="modify-user" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit'">修改用户信息</a> </span>
			<span><a
			id="reset-password" class="easyui-linkbutton"
			data-options="iconCls:'icon-refresh'">重置密码</a> </span>
			 <span><a
			id="deleting-user" class="easyui-linkbutton"
			data-options="iconCls:'icon-remove'">删除用户</a> </span>
			 <span><a
			id="all-user" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload'">显示所有用户</a> </span> 
			<span><input
			id="query-user" class="easyui-searchbox"
			data-options="label:'搜索:',prompt:'请输入用户姓名',width:300,
			    searcher:function(value,name){
			       $('#yk-uesr-info').datagrid({
			          url:'query-Some-Name',
			          method:'post',
			          queryParams:{uname:value}
			       });
			       $('#yk-uesr-info').datagrid('reload');
			       $('#query-user').searchbox('clear');
			    }
			    
			" />
		</span> 
		<span><a id="empower-user" class="easyui-linkbutton"
			data-options="iconCls:'icon-more'">给用户分配角色</a> </span>

	<div id="yk-role-to-user-sq" class="easyui-dialog"
		style="display: none; overflow: scroll;"
		data-options="title:'给用户分配角色',width:300,height:500,closed:true,
		             resizable:true,modal:true,bodyCls:'by',buttons:'#user-grant-role'">
		<ul id="tree-user-role"
			data-options="checkbox:true,method:'get',animate:true,lines:true"></ul>
	</div>
	<div id="user-grant-role">
		<a href="#" id="user-grant-roles-ave" class="easyui-linkbutton"
			data-options="iconCls:'icon-ok'">保存</a> <a href="#"
			id="user-grant-role-close" class="easyui-linkbutton"
			data-options="iconCls:'icon-cancel'">关闭</a>
	</div>

	<div id="yk-update-user" class="easyui-dialog"
		data-options="title:'修改用户信息',width:500,height:370,closed:true,
	     href:'user-update',method:'get',bodyCls:'by',buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				 $('#userfm').form({
				    onSubmit:function(params){
				       return $(this).form('validate');
				    },
				    success:function(v){
				       v = eval('(' + v + ')');
				       if(v.success){
				          $('#yk-update-user').window('close');
				          $('#yk-uesr-info').datagrid('reload');
				          $.messager.alert('提示', '修改成功！');
				       }else{
				          $('#yk-update-user').window('close');
				          $.messager.alert('提示', v.message);
				       }
				   }
				 }).submit();
				}
				
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#yk-update-user').window('close');
				}
			}],
			onLoad:function(){
			  var row = $('#yk-uesr-info').datagrid('getSelected');
			  var uId = row.uId;
			  $('#userfm').form('load','get-One-User?uId='+uId);
			},
			onOpen:function(){
			  var row = $('#yk-uesr-info').datagrid('getSelected');
			  var uId = row.uId;
			  $('#userfm').form('load','get-One-User?uId='+uId);
			}">
	</div>

	<div id="yk-add-user" class="easyui-dialog"
		data-options="title:'添加用户',width:500,height:370,closed:true,
	     href:'user-add',method:'get',bodyCls:'by',buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				$('#user-f') .form({
				 onSubmit:function(params){
				     return $(this).form('validate');
				 },
				 success:function(v){
				   v = eval('(' + v + ')');
				   if(v.success){
				        $('#yk-add-user').window('close');
				        $('#yk-uesr-info').datagrid('reload');
				         $.messager.alert('提示', '添加成功！');
				   }else{
				      $('#yk-add-user').window('close');
				       $.messager.alert('提示', v.message);
				   }
				 }
				}).submit(); 
				}	
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#yk-add-user').window('close');
				}
			}],
				onOpen:function(){
				$('#user-f').form('clear'); 
				},
				onLoad:function(){
				$('#user-f').form('clear'); 
				}">
	</div>
</body>
</html>